
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Dim roleId As Integer = UserAuthorization.CurrentUser.RoleId
        If Not Me.IsPostBack Then
            If UserAuthorization.CurrentUser.IsSingleParticipantUser = True Then
                SetParticipantHomePageLayout()
            End If
            If UserAuthorization.CurrentUser.RoleId = Cdm.DataCore.UserSecurity.Role.RoleType.SysAdmin Then
                Response.Redirect("admin/users.aspx")
            End If
            'Me.NameLabel.Text = GetUserDisplayName()
            'Me.WelcomeLabel.Text = String.Concat("Welcome to ", Application("AppName"), ": ")
            PopulateQuickLinks(roleId)
        Else
            If Request("HiddenScrollPositionValue") IsNot Nothing Then
                'Me.Page.Form.Attributes.Add("onload", "getScroll('" + Me.DashboardDiv.ClientID + "'," + Request("HiddenScrollPositionValue") + ");")
                ClientScript.RegisterStartupScript(GetType(Page), "startup", "<script type=""text/javascript"" language=""javascript""> getScroll('" + Me.DashboardDiv.ClientID + "'," + Request("HiddenScrollPositionValue") + "); </script>")

            End If
        End If
        ClientScript.RegisterOnSubmitStatement(GetType(Page), "frmsubmit", "setScrollById('" + Me.DashboardDiv.ClientID + "');")
            PopulateDashboard(roleId)
    End Sub

    Private Sub SetParticipantHomePageLayout()
        'Me.QuickLinksDiv.Style("top") = "220px"
        'Me.QuickLinksDiv.Style("width") = "279px"
        Me.LeftCornerImage.Style("top") = "-15px"
        Me.RightCornerImage.Style("top") = "-15px"
        Me.RightCornerImage.Style("left") = "258px"
        Me.QuickLinksSpan.Style("font-size") = "1.5em"
        'Me.WelcomeDiv.Style("visibility") = "visible"
        SetWelcomeLiteral()
        'Me.QuickLinksItemsDiv.Style("top") = "278px"
        'Me.QuickLinksItemsDiv.Style("width") = "279px"

        'Me.GradientImage.Style("width") = "279px"

        'Me.QuickLinksItemsSpan.Style("left") = "28px"
        'Me.QuickLinksItemsSpan.Style("top") = "10px"
        Me.DashboardDiv.Style("left") = "345px"
        Me.DashboardDiv.Style("top") = "220px"
        'Me.DashboardDiv.Style("width") = "620px"
        Me.DashboardDiv.Style("height") = "287px"

    End Sub
    ''' <summary>
    ''' Write a Table to Welcome the user
    ''' This is called for Participants, Reps, and Legal Guardians
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetWelcomeLiteral()
        Dim welcomeStringBuilder As New StringBuilder()
        welcomeStringBuilder.Append("<table cellpadding=""0"" cellspacing=""0"" ")
        welcomeStringBuilder.Append("style=""visibility:collapse; height:0px;"" border=""0"">")
        welcomeStringBuilder.Append("<tr style=""height:30px"" valign=""bottom""><td style=""width:20px;""></td>")
        welcomeStringBuilder.Append("<td style=""width:945px;""><div id=""WelcomeDiv"" runat=""server"">")
        welcomeStringBuilder.Append("<span style=""font-family: Arial, MS Sans Serif, Verdana, Sans-Serif; font-weight:bolder; font-size: 1em; color:#21334B"">")
        welcomeStringBuilder.Append("Welcome to PersonalChoice:  </span>")
        welcomeStringBuilder.Append("<span style=""font-family: Arial, MS Sans Serif, Verdana, Sans-Serif; font-weight:bolder; font-size: 1em; color:#A04111"">")
        welcomeStringBuilder.Append(GetUserDisplayName())
        welcomeStringBuilder.Append("</span></div></td></tr></table>")
        Me.WelcomeLiteral.Text = welcomeStringBuilder.ToString()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    End Sub


    Public Function GetDisplayName(ByVal inputValue As String) As String
        Return EntityController.ReplaceDisplayName(inputValue)
    End Function

    Private Function GetUserDisplayName() As String
        Dim usr As Cdm.DataCore.UserSecurity.CDMUser = UserAuthorization.CurrentUser
        Dim displayName As String = usr.FirstName
        If usr.MiddleName.Length > 0 Then
            displayName = String.Concat(displayName, " ", usr.MiddleName.Substring(0, 1).ToUpper, ".")
        End If
        displayName = String.Concat(displayName, " ", usr.LastName)
        Return displayName
    End Function

    Private Sub PopulateQuickLinks(ByVal roleId As Integer)

        Me.QuickLinksRepeater.DataSource = Cdm.DataCore.Navigation.NavigateQuickLinks.ListByUser(UserAuthorization.CurrentUser.Id)
        Me.QuickLinksRepeater.DataBind()
        Dim quickLinksSize As Integer = 25 * QuickLinksRepeater.Items.Count
        'Me.QuickLinksItemsDiv.Style("height") = quickLinksSize.ToString() + "px"
        'Me.GradientImage.Style("height") = quickLinksSize.ToString() + "px"
    End Sub

    Private Sub PopulateDashboard(ByVal roleId As Integer)
        Me.DashBoardRepeater.DataSource = Cdm.DataCore.Navigation.Dashboard.ListByRole(roleId)
        Me.DashBoardRepeater.DataBind()
    End Sub

    Protected Sub rptDashBoard_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles DashBoardRepeater.ItemDataBound
        Dim DashboardPanel As Panel = e.Item.FindControl("DashboardItemPanel")
        Dim DashBoardDataItem As Cdm.DataCore.Navigation.Dashboard
        DashBoardDataItem = CType(e.Item.DataItem, Cdm.DataCore.Navigation.Dashboard)
        Dim ctl As Control = Me.LoadControl("../DashboardControls/" & DashBoardDataItem.ControlName)
        Dim dash As IDashBoard = ctl
        dash.Title = DashBoardDataItem.Title
        DashboardPanel.Controls.Add(ctl)
    End Sub

    Private Sub TestEmail()
        Dim hostServer As String = "webmail.anexinet.com"
        Dim fromAddress As String = "dhoran@anexinet.com"
        Dim fromDisplayName As String = "CDM Application"
        Dim appName As String = "Consumer Directed Module"
        Dim subject As String = "Welcome to " & appName
        Dim bodyText As String = String.Concat("Dear Barbara Schneider", vbCrLf, vbCrLf)
        bodyText = String.Concat(bodyText, "Generic Testing welcomes you to ", appName, ".", vbCrLf)
        bodyText = String.Concat(bodyText, vbCrLf)
        bodyText = String.Concat(bodyText, "You have just been granted access to our system as a new user of type: Participant")
        bodyText = String.Concat(bodyText, vbCrLf)
        bodyText = String.Concat(bodyText, "Use the following information to log into our system")
        bodyText = String.Concat(bodyText, vbCrLf, vbCrLf)
        bodyText = String.Concat(bodyText, "Homepage: http:/cdm.anexinet.com/cdmGeneral/default.aspx ")
        bodyText = String.Concat(bodyText, vbCrLf)
        bodyText = String.Concat(bodyText, vbCrLf)
        bodyText = String.Concat(bodyText, "Logon id: bbbbb")
        bodyText = String.Concat(bodyText, vbCrLf)
        bodyText = String.Concat(bodyText, "Password: aaaaa ")
        bodyText = String.Concat(bodyText, vbCrLf, vbCrLf)
        bodyText = String.Concat(bodyText, "Barbara - this is a format test only - can you send back to me, so I can see what your email sees? Thanks.")


        Cdm.AppServices.SendEmail.Send(hostServer, fromAddress, fromDisplayName, "bschneid@ptd.net", subject, bodyText)
        Cdm.AppServices.SendEmail.Send(hostServer, fromAddress, fromDisplayName, "dhoran@anexinet.com", subject, bodyText)

    End Sub

    Private Sub TestEmailHTML()
        Dim hostServer As String = "webmail.anexinet.com"
        Dim fromAddress As String = "dhoran@anexinet.com"
        Dim fromDisplayName As String = "CDM Application"
        Dim appName As String = "Consumer Directed Module"
        Dim subject As String = "Welcome to " & appName
        Dim bodyText As String = String.Concat("Dear Barbara Schneider", "<BR>", "<BR>")
        bodyText = String.Concat(bodyText, "Generic Testing welcomes you to ", appName, ".", "<BR>")
        bodyText = String.Concat(bodyText, "<BR>")
        bodyText = String.Concat(bodyText, "You have just been granted access to our system as a new user of type: Participant")
        bodyText = String.Concat(bodyText, "<BR>")
        bodyText = String.Concat(bodyText, "Use the following information to log into our system")
        bodyText = String.Concat(bodyText, "<BR>", "<BR>")
        bodyText = String.Concat(bodyText, "Homepage: <A href=""http://cdm.anexinet.com/cdmGeneral/default.aspx"">http:/cdm.anexinet.com/cdmGeneral/default.aspx</A> ")
        bodyText = String.Concat(bodyText, "<BR>")
        bodyText = String.Concat(bodyText, "<BR>")
        bodyText = String.Concat(bodyText, "Logon id: bbbbb")
        bodyText = String.Concat(bodyText, "<BR>")
        bodyText = String.Concat(bodyText, "Password: aaaaa ")
        bodyText = String.Concat(bodyText, "<BR>", "<BR>")
        bodyText = String.Concat(bodyText, " 2nd TEST EMAIL -- Barbara - I made a modification - could you tell me what the deal ")


        Cdm.AppServices.SendEmail.Send(hostServer, fromAddress, fromDisplayName, "bschneid@ptd.net", subject, bodyText)
        Cdm.AppServices.SendEmail.Send(hostServer, fromAddress, fromDisplayName, "dhoran@anexinet.com", subject, bodyText)
        Cdm.AppServices.SendEmail.Send(hostServer, fromAddress, fromDisplayName, "dennyandbeth@yahoo.com", subject, bodyText)

    End Sub
End Class
